﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.ComponentModel.DataAnnotations;

namespace Domain.Test
{
    [TestClass]
    public class UnitTestAddress
    {
        [TestMethod]
        public void WhenValidatingInvalidAddress_ResultShouldContainOneMessage()
        {
            Address cut = new Address();

            var context = new ValidationContext(cut, serviceProvider: null, items: null);
          
            var result = cut.Validate(context);

            List<ValidationResult> resultToList = result.ToList();
            Assert.IsNotNull(resultToList);
            Assert.IsTrue(resultToList.Count == 1);


            foreach (var validationResult in resultToList)
            {
                Console.WriteLine(validationResult.ErrorMessage);
            }

        }


        [TestMethod]
        public void WhenValidatingAddressWithPostalCode_ResultShouldContainNoMessage()
        {
            Address cut = new Address() { PostcalCode="1000"};

            var context = new ValidationContext(cut, serviceProvider: null, items: null);

            var result = cut.Validate(context);

            List<ValidationResult> resultToList = result.ToList();
            Assert.IsNotNull(resultToList);
            Assert.IsTrue(resultToList.Count == 0);


          

        }


        [TestMethod]
        public void WhenValidatingAddressWithPlaceName_ResultShouldContainNoMessage()
        {
            Address cut = new Address() { PostcalCode = "abcd" };

            var context = new ValidationContext(cut, serviceProvider: null, items: null);

            var result = cut.Validate(context);

            List<ValidationResult> resultToList = result.ToList();
            Assert.IsNotNull(resultToList);
            Assert.IsTrue(resultToList.Count == 0);




        }
    }
}
